package it.koutifaris.travianmap.view.mainview;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.context.HasApplicationContex;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class MainListViewImpl extends HasApplicationContex implements MapListView {

	@Override
	public ListView getListView() {
		return (ListView) getActivity().findViewById(R.id.mapListView);
	}

	@Override
	public void setOpenServerMenuItemClickHandler(Menu menu, OnMenuItemClickListener clickListener) {
		MenuItem menuItem = menu.findItem(R.id.openServers);
		menuItem.setOnMenuItemClickListener(clickListener);
	}

	@Override
	public View newItemView(ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		return inflater.inflate(R.layout.map_server_item, parent, false);
	}

	@Override
	public ServerItemView viewItemFor(View itemView) {
		return new ServerItemViewImpl(itemView);
	}

}
